//
//  SpotImgCollectionCell.swift
//  swiftProject
//
//  Created by ZhangSai on 2021/7/6.
//

import UIKit

class SpotImgCollectionCell: UICollectionViewCell {
    
    typealias ClickEditCellBlock = () -> Void
    var clickEditCellBlock : ClickEditCellBlock!
    typealias ClickImageViewCellBlock = () -> Void
    var clickImageViewCellBlock : ClickImageViewCellBlock!
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.contentView.backgroundColor = UIColor.init(hexString: "#D8D8D8")
        self.setupView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setupView()  {
        self.contentView.addSubview(self.imageView)
        self.contentView.addSubview(self.editImageView)
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        imageView.snp.makeConstraints { (make) in
            make.top.equalTo(0);
            make.left.equalTo(0);
            make.right.equalTo(0);
            make.bottom.equalTo(0);
        }
        editImageView.snp.makeConstraints { (make) in
            make.top.equalTo(0);
            make.right.equalTo(0);
            make.width.height.equalTo(20);
        }
    }
    
    @objc func tagDidCLick(tap:UIGestureRecognizer) {
        if (clickEditCellBlock != nil) {
            clickEditCellBlock()
        }
    }
    @objc func editImageViewCLick(tap:UIGestureRecognizer) {
        if (clickImageViewCellBlock != nil) {
            clickImageViewCellBlock()
        }
    }
    lazy var imageView: UIImageView = {
        let imageView = UIImageView.init()
        imageView.isUserInteractionEnabled = true
        imageView.image = UIImage.init(named: "order_placeholderImg")
        imageView.contentMode = .scaleAspectFit
        imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(editImageViewCLick)))
        return imageView
    }()
    lazy var editImageView:UIImageView = {
        let editImageView = UIImageView.init()
        editImageView.isUserInteractionEnabled = true
        editImageView.image = UIImage.init(named: "senderOrder_Image_cliear")
        editImageView.contentMode = .scaleAspectFill
        editImageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(tagDidCLick)))
        return editImageView
    }()
}
